using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MimeCloud.Foundations.Extensions
{
    public static class DirectoryInfoExtensions
    {
        public static DirectoryInfo ExistingOrNewSubdirectory(this DirectoryInfo parentDir, string subdirectoryName)
        {
            return parentDir.GetDirectories().Where(dir =>
                            String.Compare(dir.Name, subdirectoryName, true) == 0
                            ).FirstOrDefault()
                            ??
                            parentDir.CreateSubdirectory(subdirectoryName);
        }
    }
}
